﻿using RepoMovies.Adapters;
using RepoMovies.Adapters.Data;
using RepoMovies.Adapters.Mock;
using RepoMovies.Data;
using RepoMovies.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RepoMovies.Controllers
{
    public class HomeController : Controller
    {
        // set up interface
        private IMoviesAdapter _adapter; 

        // Constructor
        public HomeController()
        {
            _adapter = new MoviesDataAdapter();
            //_adapter = new MoviesMockAdapter();
        }
        // overload...
        public HomeController(IMoviesAdapter adapter)
        {
            _adapter = adapter;
        }
        

        // READ...
        public ActionResult Index()
        {
            MoviesIndexVm iVm = _adapter.GetAllMovies();
            return View(iVm);
        }

        // CREATE - show Create page
        [HttpGet]
        public ActionResult Create()
        {
            CreateMovieVm cVm = new CreateMovieVm();
            return View(cVm);
        }
        // CREATE - accept vars from Create page
        [HttpPost]
        public ActionResult Create(CreateMovieVm cVm)
        {
            // create - talk to Arrat, Singleton
            _adapter.CreateMovie(cVm);
            return RedirectToAction("Index");
        }





        //
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}